package b4.view
{
	import b4.ApplicationFacade;
	import b4.model.SmartBirdExtension;
	import b4.model.vo.player.Equip;
	import b4.view.component.humanBeing.HumanBeing;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class HumanBeingMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "humanBeingMediator";
		public static const LOAD_EQUIPMENT:String = "loadEquipment";
		public static const UPON_EQUIPMENT_BACK:String = "uponEquipmentBack";
		public function HumanBeingMediator(viewComponent:Object = null)
		{
			super(NAME, viewComponent);
		}
		
		override public function listNotificationInterests():Array
		{
			return [
					ApplicationFacade.MAINROLE_LOADED,
					HumanBeingMediator.LOAD_EQUIPMENT,
					HumanBeingMediator.UPON_EQUIPMENT_BACK
			]
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			switch ( name )
			{
				case ApplicationFacade.MAINROLE_LOADED:
					humanBeing.showRole(simpleClient.vo.me.pack);
				case HumanBeingMediator.LOAD_EQUIPMENT:
					if (body is Equip)
					{
						var equip:Equip = body as Equip;
						simpleClient.takeOnEquip(equip.id);
					}
					break;
				case HumanBeingMediator.UPON_EQUIPMENT_BACK:
					trace("=========================穿装备成功！");
					break;
			}
		}
		
		override public function onRegister():void
		{
			humanBeing.show();
			simpleClient.getMainRole();
		}
		
		override public function onRemove():void
		{
			humanBeing.dispose();
		}
		
		private function get humanBeing():HumanBeing
		{
			return viewComponent as HumanBeing;
		}
		
		private function get simpleClient():SmartBirdExtension
		{
			return facade.retrieveProxy(SmartBirdExtension.NAME) as SmartBirdExtension;
		}
	}
}
